#####################################################################################
####
####  Graphs for Term Limits Paper
####
#####################################################################################


library (foreign)


## Graph for Primary Unconditional Models

GraphingDataHawkish <- read.dta("/Users/Jeff/Dropbox/TermLimits/D6/Analysis/Models/Index/Unconditional/Primary/Confounding/PredictedValues.dta")
GraphingDataHawkish2 <- read.dta("/Users/Jeff/Dropbox/TermLimits/D6/Analysis/Models/Index2/Unconditional/Primary/Confounding/PredictedValues.dta")
GraphingDataMil <- read.dta("/Users/Jeff/Dropbox/TermLimits/D6/Analysis/Models/Unconditional/Primary/Confounding/PredictedValues.dta")

op <- par(mfrow = c(2,3), omi=c(1.25,.5,.25,0))
{
    
par(mai=c(0.3,0.2,0.2,0.2))
plot(c(-.25,1.25),c(0,.1),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
mtext("Pr(Conflict Initiation)", side=2,line=3,cex=1)
axis(1, at=c(0,1), labels=c("Accountable","Term Limited"),cex=1)
axis(2, at=c(0,0.05,.1),cex.axis=1)
mtext("Model 1", side=3,line=1,cex=1)

arrows(0,GraphingDataHawkish$lo0,0, GraphingDataHawkish$hi0,code=3,angle=90,col="black",lwd=1.25)
points(0,GraphingDataHawkish$prob_hat0,pch=15,col="red",cex=1.75)

arrows(1,GraphingDataHawkish$lo1,1, GraphingDataHawkish$hi1,code=3,angle=90,col="black",lwd=1.25)
points(1,GraphingDataHawkish$prob_hat1,pch=18,col="blue",cex=2)

       


par(mai=c(0.3,0.2,0.2,0.2))
plot(c(-.25,1.25),c(0,.1),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
axis(1, at=c(0,1), labels=c("Accountable","Term Limited"),cex=1)
axis(2, at=c(0,0.05,.1),cex.axis=1)
mtext("Model 2", side=3,line=1,cex=1)

arrows(0,GraphingDataHawkish2$lo0,0, GraphingDataHawkish2$hi0,code=3,angle=90,col="black",lwd=1.25)
points(0,GraphingDataHawkish2$prob_hat0,pch=15,col="red",cex=1.75)

arrows(1,GraphingDataHawkish2$lo1,1, GraphingDataHawkish2$hi1,code=3,angle=90,col="black",lwd=1.25)
points(1,GraphingDataHawkish2$prob_hat1,pch=18,col="blue",cex=2)





par(mai=c(0.3,0.2,0.2,0.2))
plot(c(-.25,1.25),c(0,.1),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
axis(1, at=c(0,1), labels=c("Accountable","Term Limited"),cex=1)
axis(2, at=c(0,0.05,.1),cex.axis=1)
mtext("Model 3", side=3,line=1,cex=1)

arrows(0,GraphingDataMil$lo0,0, GraphingDataMil$hi0,code=3,angle=90,col="black",lwd=1.25)
points(0,GraphingDataMil$prob_hat0,pch=15,col="red",cex=1.75)

arrows(1,GraphingDataMil$lo1,1, GraphingDataMil$hi1,code=3,angle=90,col="black",lwd=1.25)
points(1,GraphingDataMil$prob_hat1,pch=18,col="blue",cex=2)



## Difference ##

par(mai=c(0.2,0.2,0.2,0.2))
plot(c(-.25,1.25),c(-.05,.05),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
mtext("Difference", side=2,line=3,cex=1)
axis(2, at=c(-.05,0,.05),cex.axis=1)
abline(h =0, col="black")

arrows(.5,GraphingDataHawkish$diff_lo0,.5, GraphingDataHawkish$diff_hi0,code=3,angle=90,col="black",lwd=1.25)
points(.5,GraphingDataHawkish$diff_hat0,pch=19,col="black",cex=1.5)




par(mai=c(0.2,0.2,0.2,0.2))
plot(c(-.25,1.25),c(-.05,.05),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
axis(2, at=c(-.05,0,.05),cex.axis=1)
abline(h =0, col="black")

arrows(.5,GraphingDataHawkish2$diff_lo0,.5, GraphingDataHawkish2$diff_hi0,code=3,angle=90,col="black",lwd=1.25)
points(.5,GraphingDataHawkish2$diff_hat0,pch=19,col="black",cex=1.5)



par(mai=c(0.2,0.2,0.2,0.2))
plot(c(-.25,1.25),c(-.05,.05),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
axis(2, at=c(-.05,0,.05),cex.axis=1)
abline(h =0, col="black")

arrows(.5,GraphingDataMil$diff_lo0,.5, GraphingDataMil$diff_hi0,code=3,angle=90,col="black",lwd=1.25)
points(.5,GraphingDataMil$diff_hat0,pch=19,col="black",cex=1.5)

}

par(op)

op <- par(usr=c(0,1,0,1), # Reset the coordinates
          xpd=NA)

legend(.4,.1, c("Electorally Accountable", "Term Limited","Pr(Conflict|Term Limited) - Pr(Conflict|Accountable)","95% Confidence Interval"), bty="n", cex=.75,col=c("red","blue","black","black"),
        lty=c(-1,-1,-1,1),pch=c(15,18,19,-1), ncol=1)











## Graph for Primary Conditional Models

GraphingDataHawkish <- read.dta("/Users/Jeff/Dropbox/TermLimits/D6/Analysis/Models/Index/Conditional/Primary/Confounding/PredictedValues.dta")
GraphingDataHawkish2 <- read.dta("/Users/Jeff/Dropbox/TermLimits/D6/Analysis/Models/Index2/Conditional/Primary/Confounding/PredictedValues.dta")
GraphingDataMil <- read.dta("/Users/Jeff/Dropbox/TermLimits/D6/Analysis/Models/Conditional/Primary/Confounding/PredictedValues.dta")



ruler0 <- GraphingDataHawkish$ruler - .15
ruler1 <- GraphingDataHawkish$ruler + .15

op <- par(mfrow = c(2,3), omi=c(1.25,.5,.25,0))
{
    
par(mai=c(0.3,0.2,0.2,0.2))
plot(c(.5,5.5),c(0,.2),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
mtext("Pr(Conflict Initiation)", side=2,line=3,cex=1)
axis(1, at=c(1,2,3,4,5), labels=c("Dove","","","","Hawk"),cex=1)
axis(2, at=c(0,.1, .2),cex.axis=1)
mtext("Model 4", side=3,line=1,cex=1)

points(ruler0,GraphingDataHawkish$prob_hat0,pch=15,col="red",cex=1.75)
points(ruler1,GraphingDataHawkish$prob_hat1,pch=18,col="blue",cex=2)

arrows(ruler0,GraphingDataHawkish$lo0,ruler0,GraphingDataHawkish$hi0,code=3,angle=90,col="black",lwd=1,length = 0.1)
arrows(ruler1,GraphingDataHawkish$lo1,ruler1,GraphingDataHawkish$hi1,code=3,angle=90,col="black",lwd=1,length = 0.1)





ruler0 <- GraphingDataHawkish2$ruler - .1
ruler1 <- GraphingDataHawkish2$ruler + .1

par(mai=c(0.3,0.2,0.2,0.2))
plot(c(.5,4.5),c(0,.2),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
axis(1, at=c(1,2,3,4), labels=c("Dove","","","Hawk"),cex=1)
axis(2, at=c(0,.1, .2),cex.axis=1)
mtext("Model 5", side=3,line=1,cex=1)

points(ruler0,GraphingDataHawkish2$prob_hat0,pch=15,col="red",cex=1.75)
points(ruler1,GraphingDataHawkish2$prob_hat1,pch=18,col="blue",cex=2)

arrows(ruler0,GraphingDataHawkish2$lo0,ruler0,GraphingDataHawkish2$hi0,code=3,angle=90,col="black",lwd=1,length = 0.1)
arrows(ruler1,GraphingDataHawkish2$lo1,ruler1,GraphingDataHawkish2$hi1,code=3,angle=90,col="black",lwd=1,length = 0.1)




par(mai=c(0.3,0.2,0.2,0.2))
plot(c(-5,5),c(0,.2),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
axis(1, at=c(-2.5,2.5), labels=c("Civilian","Military"),cex=1)
axis(2, at=c(0,.1,.2),cex.axis=1)
mtext("Model 6", side=3,line=1,cex=1)

arrows(-3.5,GraphingDataMil$lo0,-3.5, GraphingDataMil$hi0,code=3,angle=90,col="black",lwd=1,length = 0.1)
arrows(-1.5,GraphingDataMil$lo1,-1.5, GraphingDataMil$hi1,code=3,angle=90,col="black",lwd=1,length = 0.1)
points(-3.5,GraphingDataMil$prob_hat0,pch=15,col="red",cex=1.75)
points(-1.5,GraphingDataMil$prob_hat1,pch=18,col="blue",cex=2)

arrows(1.5,GraphingDataMil$lo01,1.5, GraphingDataMil$hi01,code=3,angle=90,col="black",lwd=1,length = 0.1)
arrows(3.5,GraphingDataMil$lo11,3.5, GraphingDataMil$hi11,code=3,angle=90,col="black",lwd=1,length = 0.1)
points(1.5,GraphingDataMil$prob_hat01,pch=15,col="red",cex=1.75)
points(3.5,GraphingDataMil$prob_hat11,pch=18,col="blue",cex=2)





par(mai=c(0.2,0.2,0.2,0.2))
plot(c(.75,5.25),c(-.15,.15),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
mtext("Difference", side=2,line=3,cex=1)
axis(1, at=c(1,2,3,4,5), labels=c("Dove","","","","Hawk"),cex=1)
axis(2, at=c(-.1,0,.1),cex.axis=1)
abline(h =0, col="black")

points(GraphingDataHawkish$ruler,GraphingDataHawkish$diff_hat0 ,pch=19,col="black",cex=1.5)
arrows(GraphingDataHawkish$ruler,GraphingDataHawkish$diff_lo0,GraphingDataHawkish$ruler,GraphingDataHawkish$diff_hi0,code=3,angle=90,col="black",lwd=1,length = 0.1)





par(mai=c(0.2,0.2,0.2,0.2))
plot(c(.75,4.25),c(-.15,.15),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
axis(1, at=c(1,2,3,4), labels=c("Dove","","","Hawk"),cex=1)
axis(2, at=c(-.1,0,.1),cex.axis=1)
abline(h =0, col="black")

points(GraphingDataHawkish2$ruler,GraphingDataHawkish2$diff_hat0 ,pch=19,col="black",cex=1.5)
arrows(GraphingDataHawkish2$ruler,GraphingDataHawkish2$diff_lo0,GraphingDataHawkish2$ruler,GraphingDataHawkish2$diff_hi0,code=3,angle=90,col="black",lwd=1,length = 0.1)




par(mai=c(0.2,0.2,0.2,0.2))
plot(c(-.25,1.25),c(-.15,.15),type="n",xaxt="n", yaxt="n", xlab="", ylab="")
x<-c(-.35,2.2)
y<-c(0,0)
lines (x,y,lty="solid", col="black")
axis(1, at=c(0,1), labels=c("Civilian","Military"),cex=1)
axis(2, at=c(-.1,0,.1),cex.axis=1)


arrows(0,GraphingDataMil$diff_lo0,0, GraphingDataMil$diff_hi0,code=3,angle=90,col="black",lwd=1.25,length = 0.1)
points(0,GraphingDataMil$diff_hat0,pch=19,col="black",cex=1.5)

arrows(1,GraphingDataMil$diff_lo01,1, GraphingDataMil$diff_hi01,code=3,angle=90,col="black",lwd=1.25,length = 0.1)
points(1,GraphingDataMil$diff_hat01,pch=19,col="black",cex=1.5)




}

par(op)

op <- par(usr=c(0,1,0,1), # Reset the coordinates
          xpd=NA)

legend(.4,.1, c("Electorally Accountable", "Term Limited","Pr(Conflict|Term Limited) - Pr(Conflict|Accountable)"), bty="n", cex=.75,col=c("red","blue","black"),
        lty=c(-1,-1,-1),pch=c(15,18,19), ncol=1)













